home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 72 / IOPROG_72.ISO / soft / Codice / Web Application in Java / eLisa / Java Web App / support / src / TabellaDB.java < prev    next >
Encoding:
Java Source  |  2003-07-02  |  902 b   |  40 lines

  1. import java.sql.*;
  2.  
  3. abstract class TabellaDB {
  4.     
  5.     Connection conn;
  6.     
  7.     public TabellaDB( Connection conn ) {
  8.         this.conn = conn;
  9.     }
  10.     
  11.     //Pattern Template Method
  12.     public void generate() throws SQLException, Exception {
  13.         try {
  14.             drop();
  15.         } catch( SQLException ex ) {
  16.             //se la tabella non esiste prosegue...
  17.         }
  18.         create();
  19.         fill();
  20.     }
  21.     
  22.     abstract void drop() throws SQLException;
  23.     abstract void create() throws SQLException;
  24.     abstract void fill() throws SQLException, Exception;
  25.     
  26.     void execute( String sql ) throws SQLException {
  27.         log( sql );
  28.         
  29.         Statement st = conn.createStatement();
  30.         st.executeUpdate( sql );
  31.         st.close();
  32.     }
  33.     
  34.     void log( String message ) {
  35.         System.out.println( message );
  36.     }
  37.     
  38.     
  39. }
  40.